/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package logica;

import datos.vhabitacion;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.connection;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
 *
 * @author Felipe
 */
public class fhabitacion {
    private conexion mysql=new conexion();
    private connection cn=mysql.conectar();
    private String sSQL="";
    public Integer totalregistros;
    
    public DefaultTableModel mostrar(String buscar){
        DefaultTableModel modelo;
        
        String [] titulos = {"ID","Numero","piso","Descripcion","Caracteristicas","Precio","Estardo","Tipo Habitacion"};
        String [] registro =new String [8];
        totalregistros =0;
        modelo =new DefaultTableModel(null, titulos);
        sSQL ="select * from habitacion where piso like '%" + buscar + "&' order by idhabitacion";
        
        try {
            Statement st=cn.createStatement();
            ResultSet rs=st.executeQuery(sSQL);
            
            while (rs.next()){
            registro [0]=rs.getString("idhabitacion");
             registro [1]=rs.getString("numero");
              registro [2]=rs.getString("piso");
               registro [3]=rs.getString("descripcion");
                registro [4]=rs.getString("caracteristicas");
                 registro [5]=rs.getString("precio_diario");
                  registro [6]=rs.getString("estado");
                   registro [7]=rs.getString("tipo_habitacion");
                   
                   totalregistros=totalregistros+1;
                   modelo.addRow(registro);
                   
            }
            
            return modelo;
            
        } catch (Exception e){
        JOptionPane.showConfirmDialog(null, e);
        return null;
        }
            
        
    }
    public boolean insertar (vhabitacion dts){
            sSQL="insert into habitacion(numero, piso, habitacion, caracteristicas, precio_diario, estado, tipo_habitacion)"+
            "values (?,?,?,?,?,?,?)";
        try {
            
            PreparedStatement pst=cn.PreparedStatement(sSQL);
            pst.SetString(1, dts.getNumero());
            pst.SetString(2, dts.getPiso());
            pst.SetString(3, dts.getDescripcion());
            pst.SetString(4, dts.getCaracteristicas());
            pst.SetDouble(5, dts.getPrecio_diario());
            pst.SetString(6, dts.getEstado());
            pst.SetString(7, dts.getTipo_habitacion());
            
            int n=pst.executeUpdate();
            
            if (n!=0) {
                return true;
            }
            else {
                return false;
            } 
            
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(null, e);
                return false;
        }
    }
    
     public boolean editar (vhabitacion dts){
         
        try {
            
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(null, e);
        }
    }
     
      public boolean eliminar (vhabitacion dts){
        try {
            
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(null, e);
        }
    }
}
